<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
	<head>
		<base href="<%=basePath%>">
		<meta charset="utf-8" />
		<%@ include file="../../share/layoutForm.jsp"%> 
	</head>
<body>
<form id="form1">
<div style="margin-left: 10px; margin-right: 10px;">
    <ul class="nav nav-tabs">
        <li class="active"><a href="#BaseInfo" data-toggle="tab">基本信息</a></li>
        <li><a href="#ExpandInfo" data-toggle="tab">扩展属性</a></li>
    </ul>
    <div class="tab-content" style="padding-top: 15px;">
        <div id="BaseInfo" class="tab-pane active" style=" padding-right: 30px;">
            <table class="form">
                <tr>
                    <td class="formTitle">工号<font face="宋体">*</font></td>
                    <td class="formValue">
                        <input id="userName" type="text" onblur="$.ExistField(this.id,'<%=basePath%>sysUser/isExist.do')" class="form-control" placeholder="请输入账户" isvalid="yes" checkexpession="NotNull" />
                    </td>
                    <td class="formTitle">密码<font face="宋体">*</font></td>
                    <td class="formValue">
                        <input id="userPwd" type="text" class="form-control" placeholder="请输入密码" isvalid="yes" checkexpession="NotNull" />
                    </td>
                </tr>
                <tr>
                    <td class="formTitle">公司<font face="宋体">*</font></td>
                    <td class="formValue">
                        <div id="organizeId" type="selectTree" class="ui-select" isvalid="yes" checkexpession="NotNull"></div>
                    </td>
                    <td class="formTitle">部门<font face="宋体">*</font></td>
                    <td class="formValue">
                        <div id="departId" type="selectTree" class="ui-select" isvalid="yes" checkexpession="NotNull"></div>
                    </td>
                </tr>
                <tr>
                    <td class="formTitle">岗位</td>
                    <td class="formValue">
                        <div id="jobId" type="select" class="ui-select"></div>
                    </td>
                    <td class="formTitle">职位</td>
                    <td class="formValue">
                        <div id="postId" type="select" class="ui-select"></div>
                    </td>
                </tr>
                <tr>
                    <td class="formTitle">姓名</td>
                    <td class="formValue">
                        <input id="realName" type="text" class="form-control" />
                    </td>
                    <td class="formTitle">性别</td>
                    <td class="formValue">
                        <div id="userSex" type="select" class="ui-select">
                            <ul>
                                <li data-value="1">男</li>
                                <li data-value="0">女</li>
                            </ul>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td class="formTitle">电话</td>
                    <td class="formValue">
                        <input id="telPhone" type="text" class="form-control" />
					</td>
					<td class="formTitle">生日</td>
                    <td class="formValue">
                        <input id="birthday" type="text" class="form-control input-wdatepicker" onfocus="WdatePicker()" />
                    </td>
                </tr>
                <tr>
                    <th class="formTitle" valign="top" style="padding-top: 4px;">备注
                    </th>
                    <td class="formValue" colspan="3">
                        <textarea id="otherMark" class="form-control" style="height: 50px;"></textarea>
                    </td>
                </tr>
            </table>
        </div>
        <div id="ExpandInfo" class="tab-pane ">
            <div class="app_layout app_preview" style="border-top: 1px solid #ccc;" id="frmpreview"></div>
        </div>
    </div>
</div>
</form>
<script>
    var keyValue = request('keyValue');
    var instanceId = "";
    var formId = "";
    $(function () {
        initControl();
    })
    //初始化控件
    function initControl() {
        //公司
        $("#organizeId").ComboBoxTree({
            url: "<%=basePath%>sysOrganize/treeJson.do",
            description: "==请选择==",
            height: "200px",
            allowSearch: true,
        }).bind("change", function () {
            var value = $(this).attr('data-value');
            //加载部门
            $("#departId").ComboBoxTree({
                url: "<%=basePath%>sysDepartment/treeJson.do?organizeId=" + value,
                description: "==请选择==",
                allowSearch: true
            });
            //加载角色
            $("#roleId").ComboBox({
                url: "<%=basePath%>sysRole/comboBox.do?organizeId=" + value,
                id: "roleId",
                text: "roleName",
                description: "==请选择==",
                allowSearch: true
            });
            //加载岗位
            $("#postId").ComboBox({
                url: "<%=basePath%>sysPost/comboBox.do?organizeId=" + value,
                id: "roleId",
                text: "roleName",
                description: "==请选择==",
                allowSearch: true
            });
        });
        //部门
        $("#departId").ComboBoxTree({
            description: "==请选择==",
            height: "200px",
            allowSearch: true
        }).bind("change", function () {
            var value = $(this).attr('data-value');
            //加载职位
            $("#jobId").ComboBox({
                url: "<%=basePath%>sysJob/comboBox.do?organizeId=" + value,
                id: "roleId",
                text: "roleName",
                description: "==请选择==",
                allowSearch: true
            });
        });
        //岗位
        $("#postId").ComboBox({
            description: "==请选择==",
            height: "200px",
            allowSearch: true
        });
        //角色
        $("#roleId").ComboBox({
            description: "==请选择==",
            height: "200px",
            allowSearch: true
        });
        //职位
        $("#jobId").ComboBox({
            description: "==请选择==",
            height: "200px",
            allowSearch: true
        });
        //性别
        $("#userSex").ComboBox({
            description: "==请选择==",
        });
		
		//获取表单
        if (!!keyValue) {
            $.SetForm({
                url: "<%=basePath%>sysUser/get.do",
                param: { keyValue: keyValue },
                success: function (data) {
					if(data.type=="0"){
						$("#form1").SetWebControls(data.rows);
						$("#organizeId").trigger("change");
						$("#departId").ComboBoxTreeSetValue(data.rows.departId).trigger("change");
						$("#postId").ComboBoxSetValue(data.rows.postId);
						$("#jobId").ComboBoxSetValue(data.rows.jobId);
						$("#birthday").val(formatDate(data.rows.birthday, "yyyy-MM-dd"));
						$("#userPwd").val("******").attr('disabled', 'disabled');
					}else{
						dialogAlert(data.message, -1);
					}
                    
                }
            });
        }
		
    }
    //保存表单
    function AcceptClick() {
        if (!$('#form1').Validform()) {
            return false;
        }
        var postData = $("#form1").GetWebControls(keyValue);
        postData["postName"] = $("#postId").attr('data-text');
        postData["jobName"] = $("#jobId").attr('data-text');
		postData["keyValue"] = keyValue;
        //var _instanceData = $("#frmpreview").frmGetData();
        //var moduleFormInstanceEntity = { "FormId": formId, "FormInstanceJson": JSON.stringify(_instanceData) };

        $.SaveForm({
            url: "<%=basePath%>sysUser/edit.do",
            param: postData,
            loading: "正在保存数据...",
            success: function (data) {
                $.currentIframe().$("#gridTable").trigger("reloadGrid");
            }
        })
    }
</script>
</body>
</html>